package com.wlf.netty.nio;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class NIOFileChannelWrite {
    public static void main(String[] args) throws Exception {
        String str = "hello world";
        
        //创建一个输出流
        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\jessi\\Desktop\\github\\test\\001.txt");

        //通过fileOutputStream 获取对应的channel
        FileChannel channel = fileOutputStream.getChannel();
        //创建一个缓冲区bytebuffer
        ByteBuffer buffer = ByteBuffer.allocate(1024);
        buffer.put(str.getBytes());
        //从写操作 转化为 读操作
        buffer.flip();

        channel.write(buffer);
        fileOutputStream.close();

    }
}
